<template>
    <h1>注册功能</h1>

    <table>
        <tr>
            <td>账号</td>
            <td>
                <input type="text" v-model="User.L_Name" >
            </td>
        </tr>

        <tr>
            <td>密码</td>
            <td>
                <input type="password" v-model="User.L_Pwd" >
            </td>
        </tr>

        <tr>
            <td colspan="2">
                <input type="button" value="注册" @click="AddLogin" >
            </td>
        </tr>

    </table>


</template>

<script setup lang="ts">
import { ref } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';

const router = useRouter();

const User = ref({
    L_Name:'',
    L_Pwd:''
})

const AddLogin = ()=>{

    if(User.value.L_Pwd == ""){
        alert('密码不能为空!');
        return;
    }

    axios({
        method:'post',
        url:'http://localhost:61480/api/Regoin/AddLogin',
        data:{
            L_Name:User.value.L_Name,
            L_Pwd:User.value.L_Pwd
        }
    })
    .then(res=>{
        if(res.data>0){
            alert('注册成功');
            router.push('/Login');
        }
        else if(res.data==-1){
            alert('账号已存在,请重新输入');
            return;
        }
        else{
            alert('注册失败');
            return;
        }
    })
    .catch(err=>{
        console.log(err);   
    })
}


</script>